package com.zero.demo.jms.util;

import com.zero.demo.jms.entity.DynamicCompDto;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author zengzr
 * @desc
 * @Date 2019/5/5 17:40
 */
@Component
@Log4j2
public class DynamicComponentUtils {

    @Autowired
    BusiDynamicCompCacheUtils busiDynamicCompCacheUtils;

    @Autowired
    DynmiaClassCacheUtils dynmiaClassCacheUtils;

    @SuppressWarnings("unchecked")
    public <T> Class<T> getClass(Long dynamicCompId, Class<T> clazz) throws Exception {
        DynamicCompDto osBusiDynamicCompDto = busiDynamicCompCacheUtils.getById(dynamicCompId);
        Class<?> targetClass = dynmiaClassCacheUtils.getClassById(osBusiDynamicCompDto.getId());
        return (Class<T>) targetClass;
    }


    public <T> T getBean(Long dynamicCompId, Class<T> clazz) throws Exception {
        T t= dynmiaClassCacheUtils.getInstanceById(dynamicCompId, clazz);
        return t;
    }
}
